import React from 'react';
import classNames from 'classnames';

export type IconSize = 'small' | 'default' | 'large';
export interface IconProps {
  type: string;
  className?: string;
  size?: IconSize;
  onClick?: React.MouseEventHandler<HTMLElement>;
  spin?: boolean;
  style?: React.CSSProperties;
}

const Icon: React.SFC<IconProps> = (props) => {
  const {
    className,
    type,
    spin,
    size,
    ...restProps
  } = props;

  let sizeCls = '';
  switch (size) {
    case 'large':
      sizeCls = 'lg';
      break;
    case 'small':
      sizeCls = 'sm';
    default:
      break;
  }

  const classString = classNames({
    [`icon-${type}`]: Boolean(type),
    'icon-spin': spin,
    [`icon-${sizeCls}`]: sizeCls,
  }, className);

  return (
    <i {...restProps} className={classString} />
  );
};

export default Icon;
